<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台欢迎页</title>

    <link rel="stylesheet" href="__PUBLIC__css/bootstrap.css" />
    <link rel="stylesheet" href="__PUBLIC__css/reset.css" />
    <link rel="stylesheet" href="__PUBLIC__css/content.css" />
    <script src="__PUBLIC__js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <style>
        td{
            vertical-align :middle;
        }
        body{
            background-color: #EFF3F6;
        }
    </style>
    <script type="text/javascript">

        function confirmd() {
            var msg = "您真的确定要删除吗?";
            if(confirm(msg)==true){
                return true;
            }else{
                return false;
            }
        }

        function edit(pos_id) {
            //替换名称和描述
            $("#name_"+pos_id).html("<input type='text' name='pos_name_"+pos_id+"' id='pos_name_"+pos_id+"' placeholder='输入新的名称' value='' style='width: 80%' required>");
            $("#des_"+pos_id).html("<input type='text' name='pos_des_"+pos_id+"' id='pos_des_"+pos_id+"' placeholder='输入新的推荐位描述' value='' style='width: 80%' required>");
            $("#but_"+pos_id).html("<input type='button' name='pos_but_"+pos_id+"' id='pos_but_"+pos_id+"' onclick='edit_ajax("+pos_id+")' value='提交' style='width: 80%' required>");
        }

        function del_ajax(id, goods_id) {
            $.ajax({
                type: 'POST',
                url: "{:url('admin/Position/goodsDel')}",
                data: {
                    id: id,
                    goods_id: goods_id
                },
                dataType: 'html',
                success: function(data){
                    if (1 == data) {
                        alert('删除成功!');
                        window.location.reload();
                    }
                },
                error: function() {
                    alert('wrong!')
                }
            })
        }

        function edit_ajax(pos_id) {
            var pos_name = $("#pos_name_"+pos_id).val();
            var pos_des = $("#pos_des_"+pos_id).val();
            $.ajax({
                type: 'POST',
                url: "{:url('admin/Position/positionEdit')}",
                data: {
                    pos_name: pos_name,
                    pos_description: pos_des,
                    pos_id: pos_id
                },
                dataType: 'html',
                success: function(data) {
                    if (1 == data) {
                        alert('修改成功!');
                        $("#name_" + pos_id).html(pos_name);
                        $("#des_" + pos_id).html(pos_des);
                        $("#but_" + pos_id).html("<a href='#' onclick='edit(" + pos_id + ")'>编辑</a>&nbsp;|<a href='{:url('admin/Position/positionDel')}?pos_id="+pos_id+"'>删除</a>&nbsp;|<a href='{:url('admin/Position/positionInfo')}?pos_id="+pos_id+"'>详情</a>");
                    }
                }
            })
        }
    </script>
</head>
<body marginwidth="0" marginheight="0">
<div class="container">
    <div class="public-nav">您当前的位置：<a href="#">管理首页</a>><a href="{:url('admin/Position/positionList')}">推荐位内容管理</a></div>
    <div class="public-content">
        <div class="public-content-header">
            <h3>查看<i style="color: red">{$pos_name}</i>下的商品列表</h3>
        </div>
        <div class="public-content-cont">
            当前推荐位下共有<i style="color: red">{$pos_count}</i>条数据
            <table class="public-cont-table">
                <tr>
                    <!--<th style="width:5%">选择</th>-->
                    <th style="background-color: #c9dae4">ID</th>
                    <th style="background-color: #c9dae4;width: 40px;">排序</th>
                    <th style="background-color: #c9dae4">商品名称</th>
                    <th style="background-color: #c9dae4">商品点击量</th>
                    <th style="background-color: #c9dae4">链接</th>
                    <th style="background-color: #c9dae4">商品加入时间</th>
                    <th style="background-color: #c9dae4">加入推荐位的时间</th>
                    <th style="background-color: #c9dae4">操作</th>
                </tr>
                {volist name="pos_list" id="pos"}
                <tr>
                    <!--<td><input type="checkbox"></td>-->
                    <td>{$pos.pos_ids|default="暂缺数据"}</td>
                    <td><input type="text" value='{$pos.pos_sort|default="暂缺数据"}' name='pos_{$pos.id|default="0"}' id="pos_{$pos.id|default='0'}" style="width: 25px;"></td>
                    <td>{$pos.title}</td>
                    <td>商品点击量：<i style="color: red">{$pos.goods_hit}</i>|优惠券点击量：<i style="color: red">{$pos.ticket_hit}</i></td>
                    <td><a href="{$pos.url}" target="_blank">商品链接</a></td>
                    <td>{$pos.update_time}</td>
                    <td>{$pos.create_time}</td>
                    <td><a href="#" onclick='return del_ajax("{$pos.id}","{$pos.content_id}")'>删除</a></td>
                </tr>
                {/volist}
                <tr>
                    <td colspan="8"><input type="button" name="button" id="button" value="排序" style="margin-left: 4%;float: left;" ></td>
                </tr>
            </table>

            <div class="page">

            </div>
        </div>
    </div>
</div>
</body>
</html>